﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class QueueUsingStacks<TItem>
    {
        readonly Stack<TItem> _first, _second;
        int _count;

        public QueueUsingStacks()
        {
            _first = new Stack<TItem>();
            _second = new Stack<TItem>();
            _count = 0;
        }

        public void EnQueue(TItem item)
        {
            _first.Push(item);
            _count++;
        }

        public TItem DeQueue()
        {
            while (_first.Count != 0)
            {
                _second.Push(_first.Pop());
            }

            if (_second.Count != 0)
            {
                return _second.Pop();
                _count--;

            }

            return default(TItem);
        }

        public int Count { get { return _count; } }
    }
}
